#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <math.h>

#include "hashz.h"

#ifdef __cplusplus
extern "C" {
#endif


static const unsigned long __primeset[] =
{
  53ul,         97ul,         193ul,       389ul,       769ul,
  1543ul,       3079ul,       6151ul,      12289ul,     24593ul,
  49157ul,      98317ul,      196613ul,    393241ul,    786433ul,
  1572869ul,    3145739ul,    6291469ul,   12582917ul,  25165843ul,
  50331653ul,   100663319ul,  201326611ul, 402653189ul, 805306457ul, 
  1610612741ul, 3221225473ul, 4294967291ul
};

static const unsigned long __tableset[8][256] =
{
   {161110358ul, 1340441565ul, 33267774ul, 611037030ul, 702202867ul, 1381695412ul, 259188886ul, 1846192327ul, 136056584ul, 112879073ul, 2068467370ul, 2108525924ul, 1536004907ul, 773636543ul, 1986009859ul, 928889548ul, 967902895ul, 1541873600ul, 1617833842ul, 125735570ul, 539028845ul, 1651444678ul, 134356479ul, 1306356598ul, 640503242ul, 53005261ul, 531635008ul, 1501035774ul, 929920051ul, 1996673042ul, 158797283ul, 2146398090ul, 1062539994ul, 1286019784ul, 2137266528ul, 738681575ul, 619107796ul, 1350964495ul, 1251750968ul, 516878684ul, 1305975394ul, 1650298069ul, 1031950217ul, 957431182ul, 230112065ul, 1365577035ul, 2085776575ul, 161121473ul, 1725169091ul, 1595268940ul, 1664611625ul, 125498601ul, 1942638579ul, 843629171ul, 829288690ul, 740080618ul, 2088824006ul, 1011851981ul, 2093261980ul, 1584888616ul, 1035674757ul, 2017406798ul, 885259859ul, 1612625009ul, 1438382116ul, 185306202ul, 805796204ul, 1114378298ul, 920804079ul, 267872074ul, 595993329ul, 678935623ul, 866780083ul, 704852523ul, 590508535ul, 1550796054ul, 1442592944ul, 59294503ul, 570023415ul, 180589309ul, 707540619ul, 871913708ul, 240507744ul, 1468779338ul, 1903985929ul, 589027702ul, 1755809271ul, 1710297607ul, 1355541433ul, 2016195792ul, 68502400ul, 673659844ul, 5964102ul, 2053394129ul, 1003255831ul, 1050791523ul, 976042485ul, 1546087358ul, 581045318ul, 1911301677ul, 1616615889ul, 1981634301ul, 1433575868ul, 780177251ul, 662046157ul, 753931860ul, 1344376879ul, 1501847169ul, 89952803ul, 116676656ul, 1779765837ul, 2008940155ul, 1103882905ul, 1457159117ul, 182003491ul, 1177714114ul, 68256054ul, 1334992995ul, 1630794641ul, 87834901ul, 1484651296ul, 777339286ul, 1094798924ul, 919569308ul, 420357996ul, 2084981562ul, 338907250ul, 134232572ul, 2140815181ul, 1755446032ul, 1293430082ul, 1766365873ul, 1631262093ul, 1722261175ul, 1388327324ul, 815248234ul, 934769382ul, 525908463ul, 1425952402ul, 2101071251ul, 607887349ul, 657580162ul, 1810376502ul, 541078753ul, 638216065ul, 201432310ul, 1867089197ul, 103948613ul, 132382450ul, 934149330ul, 399596119ul, 219012521ul, 935472136ul, 1212083613ul, 151688347ul, 1026472662ul, 1840336509ul, 2112576534ul, 59022915ul, 1346637413ul, 1406525078ul, 1697145086ul, 1059464477ul, 585455685ul, 932544654ul, 158543964ul, 1968839901ul, 1153719908ul, 137862622ul, 39863881ul, 1892704323ul, 336392862ul, 2103456928ul, 1393514672ul, 579180572ul, 1700376431ul, 1640254646ul, 829731393ul, 1908671805ul, 1883823359ul, 1454306832ul, 1024330190ul, 2071896042ul, 1216758919ul, 1929448022ul, 1127141606ul, 2117376906ul, 921061560ul, 197912977ul, 297056707ul, 1017257667ul, 507596081ul, 59881583ul, 1193449782ul, 641514852ul, 114556229ul, 583182117ul, 1526954460ul, 346878616ul, 2053192830ul, 1374625095ul, 1939502694ul, 256115910ul, 11414527ul, 1111275376ul, 1509086657ul, 1835435825ul, 1824267859ul, 1375532606ul, 2141203208ul, 658620218ul, 1638141188ul, 1333642299ul, 272224396ul, 602766677ul, 1454637168ul, 1105131902ul, 1435901482ul, 1543449655ul, 1302236335ul, 1753328750ul, 2009267529ul, 1521628675ul, 999395577ul, 872750761ul, 669471719ul, 1174991769ul, 1794780336ul, 941549931ul, 2123264646ul, 1085736464ul, 1563763447ul, 1091518989ul, 717325083ul, 909347513ul, 1737937209ul, 1430889561ul, 1577981935ul, 1697146916ul, 362188918ul, 969022094ul, 1467164808ul, 1453190971ul, 1716476026ul, 1151496239ul, 1353827955ul, 607288115ul, 1888230435ul, 704223619ul, 664783925ul, 1687288452ul, 1378368648ul, 1792225864ul, 1609424498ul, 922604099ul, 609957747 },
   {1471788942ul, 295688755ul, 36722672ul, 182765914ul, 1224289603ul, 262200079ul, 367075712ul, 421010647ul, 827004861ul, 223004365ul, 1169138345ul, 397381303ul, 1254426980ul, 1922718158ul, 1159852797ul, 17012789ul, 1207425491ul, 398342810ul, 1499194436ul, 1757893312ul, 908478730ul, 849724721ul, 314103340ul, 1598390421ul, 870110527ul, 430243715ul, 1424651945ul, 473034848ul, 574980744ul, 363132458ul, 393569593ul, 1074640771ul, 1801416621ul, 658089414ul, 971959192ul, 1020123288ul, 1960518220ul, 1130068396ul, 1485114985ul, 1036824816ul, 1921905944ul, 768900116ul, 1907346139ul, 953988490ul, 799679039ul, 184437024ul, 1764194128ul, 1460577603ul, 545499339ul, 1529038577ul, 68616170ul, 152378709ul, 320079773ul, 1382348123ul, 489566218ul, 654597770ul, 1588325721ul, 6925063ul, 1864153417ul, 1136073034ul, 322543964ul, 496811134ul, 1133677978ul, 2045972805ul, 1146601300ul, 1000260648ul, 1101361265ul, 1043595029ul, 1282561857ul, 1106059217ul, 858604192ul, 1216709149ul, 281524281ul, 186274451ul, 235677809ul, 746566315ul, 1341465992ul, 522260030ul, 1192684663ul, 620161598ul, 367161830ul, 1579865272ul, 780951859ul, 413991064ul, 1742875846ul, 1331037755ul, 1741714493ul, 1778388344ul, 207737957ul, 1512425432ul, 1307373333ul, 650185837ul, 626110954ul, 1446563110ul, 176537563ul, 1693282111ul, 1329229034ul, 438903491ul, 106028551ul, 102794645ul, 214707956ul, 1323661127ul, 1348132575ul, 1654607805ul, 834037706ul, 1016101631ul, 1844249263ul, 1439803087ul, 1398942853ul, 1564508423ul, 829840104ul, 1901772027ul, 1770384558ul, 130433165ul, 1036200029ul, 1669682983ul, 355961532ul, 306964625ul, 630532612ul, 591482497ul, 103837501ul, 974461013ul, 1973226701ul, 631370860ul, 1570865404ul, 1127374933ul, 1978973901ul, 1182725116ul, 710892558ul, 1945028258ul, 2010422041ul, 1495353442ul, 598708113ul, 253165380ul, 1617761719ul, 1235778064ul, 864099474ul, 420992618ul, 210074824ul, 167081338ul, 1474176612ul, 1566159163ul, 1353233011ul, 1917213351ul, 296399868ul, 2082173228ul, 284672730ul, 9432633ul, 355209368ul, 1542200392ul, 1058531157ul, 462401866ul, 141893143ul, 127578077ul, 266146075ul, 880371847ul, 1080085658ul, 638107751ul, 2047997063ul, 578148250ul, 1842583399ul, 487008704ul, 2059519841ul, 1586934106ul, 104755330ul, 1062603943ul, 188222380ul, 4840482ul, 10909962ul, 1490524216ul, 895866429ul, 1489706206ul, 1540196879ul, 1451450735ul, 413467636ul, 1037836989ul, 86803893ul, 1548345376ul, 1224113375ul, 1592428428ul, 1411280591ul, 42369620ul, 651361613ul, 331298901ul, 1817893456ul, 1762549900ul, 1627650631ul, 17285297ul, 692762261ul, 1987211446ul, 1931631768ul, 1442416580ul, 1770905087ul, 349491275ul, 1115106133ul, 1809277394ul, 1887803647ul, 1996871734ul, 118094869ul, 995240744ul, 227051777ul, 497488360ul, 1597945764ul, 1258599045ul, 1487062543ul, 1910204244ul, 729940509ul, 511829119ul, 1635720949ul, 1513495546ul, 31814737ul, 192752884ul, 105299107ul, 1063583492ul, 1335582349ul, 24004745ul, 1549043239ul, 1925550565ul, 1793571536ul, 1346173239ul, 189266241ul, 129242156ul, 947755309ul, 291997971ul, 162229592ul, 2093257510ul, 994274370ul, 487262336ul, 863054715ul, 1095118645ul, 1083283318ul, 44101918ul, 1441520348ul, 40359861ul, 1020304459ul, 135967605ul, 1108442869ul, 346339282ul, 879889986ul, 1795869244ul, 1017527869ul, 1726574052ul, 683051711ul, 924964721ul, 763479627ul, 1659671829ul, 1623132689ul, 1190346603ul, 1995725256ul, 1048189588ul, 1535429122ul, 1514224683ul, 1794440041ul, 1680996990ul, 1479895691ul, 1686983953 },
   {108501917ul, 1799495686ul, 1947777731ul, 1837169041ul, 1364647610ul, 469565391ul, 696874709ul, 856046256ul, 1917135556ul, 1715016793ul, 1715034786ul, 1393610692ul, 1933806859ul, 1652903336ul, 1315289847ul, 1333587361ul, 327995723ul, 1181790744ul, 1868957960ul, 413997565ul, 861411035ul, 1534216643ul, 592898072ul, 624158255ul, 1831168691ul, 2056326125ul, 164270393ul, 780196101ul, 1327148766ul, 1707260525ul, 337956542ul, 1589020149ul, 218473604ul, 1493863813ul, 1576923994ul, 1879496122ul, 1209005416ul, 811420686ul, 1323462533ul, 1129331623ul, 1144717050ul, 1980768715ul, 1446068179ul, 1895554596ul, 567443010ul, 383341923ul, 850052910ul, 435667190ul, 682141051ul, 601592540ul, 1607494863ul, 1901088796ul, 1339141404ul, 586950688ul, 1490866143ul, 1770385567ul, 653154487ul, 924142098ul, 717334094ul, 1459534902ul, 1557520651ul, 641990550ul, 1893581266ul, 817874705ul, 395553461ul, 965615292ul, 119030954ul, 233470455ul, 368480388ul, 1419265518ul, 349373009ul, 203895955ul, 1775008000ul, 1501547676ul, 680556720ul, 1028522822ul, 1474797949ul, 1577072380ul, 1171892443ul, 718740888ul, 506904396ul, 1129776886ul, 1640191415ul, 1796570442ul, 858743503ul, 1493123923ul, 1175563672ul, 818037750ul, 1734460669ul, 181153510ul, 255577929ul, 935786032ul, 127135245ul, 250581235ul, 214974014ul, 895935270ul, 46058592ul, 715871175ul, 1516830819ul, 1859935140ul, 1815528169ul, 959831776ul, 649309826ul, 596258572ul, 904717688ul, 1908747443ul, 471295004ul, 1814555596ul, 555819617ul, 714342837ul, 1603720903ul, 1549759438ul, 2097978107ul, 79775069ul, 36155317ul, 1611174046ul, 1188368381ul, 333706667ul, 1818604969ul, 1808017362ul, 2120549898ul, 958855550ul, 1050228273ul, 1365992520ul, 1221806538ul, 609262165ul, 225910963ul, 873722814ul, 26013087ul, 877600891ul, 146838915ul, 1113276939ul, 782757136ul, 889033502ul, 1399645962ul, 1541410995ul, 571349028ul, 760081971ul, 181716406ul, 1984305860ul, 592001481ul, 747828334ul, 1771415482ul, 774593741ul, 547288246ul, 740713940ul, 1917299253ul, 342522530ul, 1735592044ul, 752528293ul, 1005421744ul, 218961570ul, 632963948ul, 1871454005ul, 1846386811ul, 195117139ul, 484249730ul, 1691806390ul, 1207940976ul, 421070032ul, 17117858ul, 1727603782ul, 1139094118ul, 339474136ul, 98323038ul, 1286729741ul, 1863049643ul, 963516384ul, 1294774560ul, 654761017ul, 582743807ul, 2032710589ul, 756856402ul, 151738409ul, 1947056831ul, 111224487ul, 1471506014ul, 193926983ul, 70501422ul, 1639288142ul, 354005143ul, 1261478027ul, 1239306463ul, 699447414ul, 260542838ul, 77273529ul, 870374744ul, 1789201684ul, 2018780652ul, 1562922927ul, 785441290ul, 964989014ul, 777889712ul, 417309154ul, 937719691ul, 773828490ul, 674895035ul, 737370721ul, 1047211620ul, 24985291ul, 2074837151ul, 1139960679ul, 1066292455ul, 1204779226ul, 1360813279ul, 1332588912ul, 2048169128ul, 11060563ul, 665561311ul, 1260050423ul, 1847403875ul, 1544850768ul, 163357627ul, 42936255ul, 551149524ul, 355549637ul, 241503933ul, 1118012309ul, 1493516702ul, 1736540063ul, 2094749292ul, 580033860ul, 531780461ul, 1251355423ul, 878598293ul, 2031479476ul, 1919009026ul, 1970580406ul, 1211209023ul, 1672777340ul, 87375556ul, 542996920ul, 581780121ul, 376948123ul, 1484580020ul, 90472391ul, 458936958ul, 1418741857ul, 804991859ul, 2056003998ul, 915024921ul, 1850929416ul, 550836997ul, 8173525ul, 2071712127ul, 325448377ul, 1376920975ul, 1917047861ul, 1741038871ul, 464387508ul, 1149816242ul, 2098604025ul, 1238438017ul, 800288773ul, 1059215736ul, 1919360344 },
   {118538851ul, 949920419ul, 1996646318ul, 143293098ul, 964012224ul, 1384860306ul, 1774333781ul, 1555668578ul, 1694690000ul, 560779355ul, 2120589254ul, 1013601120ul, 628084705ul, 784837302ul, 1703630678ul, 1403739570ul, 714557670ul, 1759976655ul, 1682746733ul, 1641354619ul, 1379468788ul, 589799025ul, 433577519ul, 94524422ul, 391167683ul, 1656897093ul, 820834705ul, 1769983174ul, 824500172ul, 1971254083ul, 153575828ul, 1517279484ul, 1807115429ul, 2107556356ul, 1288200842ul, 1702735480ul, 584217586ul, 340127169ul, 1872622676ul, 1585111453ul, 619700933ul, 1612150827ul, 709151499ul, 747806576ul, 1856858572ul, 1109962060ul, 771101447ul, 769871953ul, 2054994461ul, 621326764ul, 1253301749ul, 1532650159ul, 1119623033ul, 1322706257ul, 414860083ul, 667591277ul, 1221991088ul, 230891190ul, 107717472ul, 742538966ul, 546559106ul, 1583993083ul, 1351599109ul, 1332249448ul, 1806453103ul, 23875692ul, 526756960ul, 2017315657ul, 639492613ul, 1881971903ul, 249597414ul, 1837233572ul, 137083907ul, 2114637913ul, 1388920459ul, 2066848468ul, 638640495ul, 1458273819ul, 846469836ul, 166259710ul, 681663499ul, 944512284ul, 1774261036ul, 1014461432ul, 528236078ul, 1455346427ul, 1801475021ul, 1988620705ul, 1141703806ul, 415739782ul, 1959556024ul, 575926572ul, 1496992912ul, 1286199943ul, 1001484429ul, 1325427394ul, 906689188ul, 83572318ul, 1302813564ul, 1308698407ul, 436794137ul, 1914936324ul, 317067744ul, 1761202778ul, 1794528364ul, 137111996ul, 403565278ul, 1902923134ul, 1745742552ul, 1094625003ul, 1919776957ul, 399503391ul, 1437302069ul, 1580153175ul, 1535251864ul, 111352018ul, 1084932714ul, 355481132ul, 965556883ul, 2092665215ul, 1776427319ul, 1910412970ul, 1425262625ul, 1106296088ul, 1933406086ul, 384339352ul, 1615330156ul, 338609773ul, 1928348018ul, 1118307907ul, 788723606ul, 946856127ul, 1666142613ul, 1871956617ul, 767693206ul, 1689741710ul, 2010811008ul, 676053540ul, 1261526045ul, 275997618ul, 94061547ul, 1115713935ul, 1058155785ul, 1376073030ul, 667087984ul, 1291241162ul, 38867945ul, 1978237332ul, 56550687ul, 2045073938ul, 1059124371ul, 665971828ul, 1983897202ul, 1383449115ul, 609491078ul, 1880796742ul, 1270200709ul, 362513263ul, 694934503ul, 746502337ul, 172746055ul, 1179025503ul, 1996104349ul, 869025360ul, 375970358ul, 319042169ul, 1992263381ul, 1097217810ul, 1535570665ul, 470773586ul, 1876364146ul, 2111573934ul, 1464131841ul, 1712967548ul, 1247540184ul, 748881353ul, 107278358ul, 379409938ul, 969193142ul, 188144084ul, 321750108ul, 704243480ul, 1394584662ul, 1192202983ul, 1929283689ul, 30980784ul, 194749949ul, 121768989ul, 1028783634ul, 1251014245ul, 391142460ul, 1964320822ul, 937657192ul, 2052626170ul, 1371316370ul, 1133847745ul, 63150005ul, 637182975ul, 2127964776ul, 78541840ul, 806331623ul, 452955423ul, 1862477436ul, 1539166843ul, 158768973ul, 61790143ul, 1148639265ul, 711673528ul, 1817904627ul, 699482718ul, 1914366107ul, 1355960989ul, 709525220ul, 1504335742ul, 1933270865ul, 781924660ul, 1465332963ul, 936320327ul, 180260303ul, 653007884ul, 304602053ul, 1258827863ul, 1038014499ul, 2026317631ul, 1208965415ul, 413373478ul, 239005883ul, 1739153131ul, 1572782578ul, 1730183616ul, 619880742ul, 565506840ul, 35126021ul, 1330955031ul, 1176297678ul, 1275700721ul, 953729186ul, 402287827ul, 1040845543ul, 1418266277ul, 1394738015ul, 54461925ul, 200462533ul, 1093918627ul, 694268699ul, 604755126ul, 2022926646ul, 403813113ul, 1028943336ul, 332686740ul, 1040646250ul, 1853679564ul, 903046225ul, 1214472695ul, 1256636317ul, 718198236 },
   {480318955ul, 714740735ul, 1668055488ul, 682179491ul, 1816234027ul, 598508156ul, 2062174220ul, 2124181390ul, 1532714551ul, 162875646ul, 753027506ul, 940684120ul, 323400144ul, 301913419ul, 1832334079ul, 225984463ul, 265279595ul, 1834752424ul, 1958388433ul, 80968172ul, 1225706796ul, 1775605367ul, 632578466ul, 1364870780ul, 6412421ul, 978744944ul, 1002966504ul, 961372523ul, 1014837225ul, 658533519ul, 1448888134ul, 929650590ul, 986387726ul, 1171291320ul, 1520231503ul, 1229140571ul, 1832199862ul, 901189965ul, 1588553572ul, 100528414ul, 1074374738ul, 1275414584ul, 736957464ul, 2015167902ul, 1439785315ul, 1692339835ul, 653700827ul, 1862700729ul, 128130966ul, 1070313883ul, 1935338260ul, 1793928494ul, 55644109ul, 1601924499ul, 1991788602ul, 1225197881ul, 537854300ul, 788571949ul, 1892546011ul, 1551185648ul, 1258278766ul, 577128530ul, 1283814458ul, 1995466697ul, 631539885ul, 1600125265ul, 1029896734ul, 1914957791ul, 323874562ul, 1102031528ul, 1203877485ul, 146068533ul, 1569944186ul, 1625744507ul, 745157400ul, 2146108524ul, 1363049233ul, 876372701ul, 1087423769ul, 1755141755ul, 370097363ul, 646624547ul, 1355490409ul, 1064419973ul, 1563086863ul, 2135846932ul, 1574360374ul, 2010683004ul, 1360819174ul, 1202277363ul, 1003542668ul, 904891565ul, 288639361ul, 244315341ul, 1559924727ul, 1489134662ul, 289699769ul, 886834077ul, 580614968ul, 1860861826ul, 1599079132ul, 1074669760ul, 1528725164ul, 2125163402ul, 761995259ul, 1840880468ul, 1331217272ul, 357362266ul, 965694447ul, 1454482334ul, 798635248ul, 1699617543ul, 1817113757ul, 790405363ul, 1376225090ul, 1342577903ul, 4591088ul, 1422471896ul, 551239179ul, 320974106ul, 72278229ul, 1714468296ul, 155488517ul, 592209007ul, 1895055340ul, 757202410ul, 537700526ul, 321756310ul, 812994178ul, 796939466ul, 1860510887ul, 1886418658ul, 885917528ul, 310829729ul, 539767939ul, 759089308ul, 963460150ul, 971070752ul, 628768124ul, 346704189ul, 284205929ul, 1321005407ul, 2009113237ul, 413038312ul, 263434868ul, 1464716244ul, 2144937274ul, 1259017975ul, 1767691402ul, 837861528ul, 1207618755ul, 1044782661ul, 1888722898ul, 454426593ul, 299544706ul, 625437624ul, 1410088356ul, 811898268ul, 1089726458ul, 693655060ul, 2075327787ul, 1612938796ul, 1838747758ul, 840830382ul, 1159806072ul, 1787213887ul, 810691004ul, 260959641ul, 593466855ul, 770896464ul, 1450576478ul, 1978182029ul, 2117493527ul, 483278996ul, 1704667620ul, 1440179702ul, 1843339818ul, 2026547767ul, 1801260546ul, 957052362ul, 1423347557ul, 1239508536ul, 2140993730ul, 674168954ul, 1947142083ul, 2046397482ul, 172962322ul, 1959711146ul, 1235788084ul, 1517213335ul, 1459119325ul, 487865297ul, 1360827080ul, 1724808159ul, 844246240ul, 345551808ul, 848153898ul, 306246418ul, 1471163896ul, 790290617ul, 99005479ul, 819484291ul, 576471533ul, 663356926ul, 935802113ul, 1391955424ul, 2119291949ul, 726317957ul, 1718200837ul, 428713645ul, 1281093653ul, 171224966ul, 1230398280ul, 913086050ul, 381497310ul, 28888797ul, 823745428ul, 952036313ul, 1400298640ul, 1362038923ul, 1495398788ul, 773332879ul, 1804105920ul, 1828354506ul, 1618399426ul, 325108978ul, 1805405125ul, 826873189ul, 1943122647ul, 67074408ul, 2003863850ul, 1523828026ul, 1909648174ul, 510399394ul, 800132017ul, 928363479ul, 1935005996ul, 1885303079ul, 97526294ul, 80400073ul, 2130674448ul, 1929254840ul, 990973269ul, 266200581ul, 799089652ul, 737772567ul, 637220709ul, 898907147ul, 655167859ul, 982364277ul, 1601848293ul, 1902601697ul, 1594593406ul, 224407224ul, 921075053ul, 183899728 },
   {1897695261ul, 393706879ul, 2111994840ul, 1210681325ul, 1057237921ul, 585416455ul, 2059566214ul, 339157198ul, 1280624844ul, 1194010056ul, 2120832487ul, 458530107ul, 1891152092ul, 543799577ul, 1520870968ul, 1539886787ul, 1392781988ul, 50294511ul, 1535393389ul, 367093039ul, 308326338ul, 170746081ul, 1941217767ul, 591704030ul, 550602634ul, 676431436ul, 1289806370ul, 925052291ul, 223502333ul, 1447580805ul, 2042451652ul, 690072431ul, 920167073ul, 740784786ul, 1794836969ul, 1307393987ul, 1870140581ul, 1778374876ul, 859936214ul, 983379258ul, 1717936691ul, 1433078487ul, 21215501ul, 2028073862ul, 195866206ul, 312574088ul, 1009825827ul, 478397862ul, 401706673ul, 1069557194ul, 808331595ul, 1278879711ul, 1570420377ul, 835777438ul, 946651278ul, 809184586ul, 1580892533ul, 610006843ul, 359437342ul, 1185711534ul, 1667655314ul, 941309118ul, 235650680ul, 2136528806ul, 1701360526ul, 1703454138ul, 80887787ul, 1525923914ul, 945901482ul, 362123238ul, 224492335ul, 1622688263ul, 195614773ul, 909858389ul, 1190984649ul, 404646472ul, 702562904ul, 1931148930ul, 849382287ul, 1926738445ul, 1018799276ul, 2134170460ul, 2028764331ul, 1755617541ul, 455583028ul, 1304961720ul, 590565544ul, 1460194104ul, 176001954ul, 1457478129ul, 1591569445ul, 2068670287ul, 805327315ul, 418839839ul, 324132984ul, 198042216ul, 1281421948ul, 43632072ul, 1647190484ul, 1402612087ul, 1175983466ul, 981892209ul, 469285094ul, 431042268ul, 223591301ul, 1609579269ul, 1966511868ul, 576707607ul, 1116855297ul, 1908177699ul, 953814839ul, 1370858198ul, 188590605ul, 1000416303ul, 689875271ul, 1753393330ul, 176884662ul, 1623229702ul, 1607073010ul, 1863459799ul, 2129152299ul, 810196440ul, 1027441469ul, 2038720152ul, 1745290887ul, 1019555357ul, 924834494ul, 44275847ul, 1734076215ul, 103478840ul, 959238488ul, 31157316ul, 1718123282ul, 1382993501ul, 1716856789ul, 415450564ul, 1424637854ul, 324596473ul, 1223140618ul, 189795220ul, 2020816667ul, 696813169ul, 489907824ul, 740795762ul, 1134119472ul, 548761324ul, 1006802315ul, 249471969ul, 1848185570ul, 1930296845ul, 1156242843ul, 1187074321ul, 1499978522ul, 521854058ul, 715653647ul, 340640453ul, 220321853ul, 1992690784ul, 1795296613ul, 1882392186ul, 1668029535ul, 1911585051ul, 588508680ul, 1744042203ul, 609770723ul, 1150520252ul, 54605557ul, 1862488905ul, 1249125410ul, 924053893ul, 1644229217ul, 2098597953ul, 876480255ul, 1328238140ul, 1938863434ul, 1484429975ul, 1438495940ul, 2106129953ul, 1556627142ul, 871547712ul, 1476277067ul, 1707071842ul, 1760765863ul, 1674912169ul, 1092108038ul, 878103471ul, 611200130ul, 481561301ul, 759738900ul, 1429468654ul, 1012011437ul, 794689012ul, 1981180810ul, 837422ul, 1804241748ul, 1949498024ul, 1611533986ul, 1754840603ul, 1537397385ul, 386827222ul, 415481831ul, 564513347ul, 1734226681ul, 1995616313ul, 973187150ul, 1795557747ul, 1400381239ul, 168767754ul, 1469567574ul, 1207200293ul, 767133735ul, 369205781ul, 755836470ul, 1761409703ul, 993137287ul, 1063310572ul, 906446873ul, 1950873048ul, 1859990116ul, 402719378ul, 1200893690ul, 1145478440ul, 1181802230ul, 1054152157ul, 61965863ul, 1451803834ul, 971362603ul, 1968544727ul, 530143418ul, 1125298815ul, 1177079050ul, 316376366ul, 1000020976ul, 964523713ul, 1935399030ul, 913272279ul, 1572097433ul, 1302923892ul, 1703984958ul, 650952517ul, 2038320115ul, 277228768ul, 1158550933ul, 739845802ul, 629592692ul, 1984746164ul, 988585531ul, 1840288544ul, 1094700233ul, 484322905ul, 1274798590ul, 1070381647ul, 798504280ul, 500932417ul, 800596936ul, 215452809 },
   {1082581783ul, 1789672939ul, 397525614ul, 726995161ul, 808594452ul, 1067975528ul, 801797511ul, 296359816ul, 480951183ul, 2008877001ul, 2116787131ul, 957208831ul, 1943569260ul, 990996930ul, 574628913ul, 1175708866ul, 1964539138ul, 1553572642ul, 2042802005ul, 1611107854ul, 2090652553ul, 21054596ul, 957789466ul, 570211703ul, 1764528841ul, 324846351ul, 368651062ul, 1738977958ul, 710238213ul, 491398527ul, 125327353ul, 1041927226ul, 1370780916ul, 1233856243ul, 514347818ul, 1674262716ul, 1849602427ul, 608993185ul, 129904660ul, 393609282ul, 816720014ul, 300938133ul, 2055979191ul, 2101231262ul, 1073637303ul, 1837271708ul, 209315878ul, 790849156ul, 1620433004ul, 233064830ul, 281266934ul, 2141157913ul, 833389518ul, 1853584059ul, 1497777052ul, 1435966326ul, 566128881ul, 234492577ul, 1267586969ul, 646042167ul, 541121342ul, 992029293ul, 2039059128ul, 1937031421ul, 1818186666ul, 1724039169ul, 1742316602ul, 1401758961ul, 997685991ul, 350808661ul, 750247376ul, 378621770ul, 164290465ul, 1193748147ul, 123407493ul, 1849635793ul, 1714753841ul, 2142194915ul, 1959274239ul, 1238617247ul, 505324447ul, 608605388ul, 90121767ul, 1718526521ul, 2064750779ul, 2115270291ul, 1430213293ul, 942529010ul, 316098054ul, 1138862674ul, 322687342ul, 193481639ul, 1863128979ul, 1216173211ul, 670365025ul, 491158004ul, 1722949126ul, 505212871ul, 1612919363ul, 129740886ul, 216744573ul, 792561132ul, 1264696893ul, 474085274ul, 804147004ul, 2011775050ul, 574682215ul, 1711664805ul, 463203774ul, 2069932174ul, 1177264758ul, 716939349ul, 699951090ul, 175727861ul, 1148336571ul, 2102561517ul, 1972237437ul, 2099810656ul, 175881926ul, 905222875ul, 1435706522ul, 594614562ul, 472393118ul, 1784315336ul, 773908496ul, 526428384ul, 1347678347ul, 1438667778ul, 398589482ul, 270219907ul, 758763282ul, 2120523939ul, 1396151216ul, 1218473809ul, 1918018652ul, 1167758829ul, 643403176ul, 162484812ul, 233633769ul, 110624428ul, 1512682002ul, 1215106512ul, 330690841ul, 1508660998ul, 257663891ul, 2133909739ul, 2144771125ul, 158755664ul, 1687163650ul, 1428571851ul, 1101369128ul, 252616922ul, 1593328119ul, 512350810ul, 1494806203ul, 1149919988ul, 854118098ul, 2013232453ul, 742459806ul, 747435500ul, 986942380ul, 789514624ul, 1088505617ul, 2091256443ul, 372158801ul, 592563341ul, 1608724826ul, 265304703ul, 1066565989ul, 1695583335ul, 5841436ul, 822496922ul, 1046477773ul, 1558037703ul, 1714233396ul, 731983327ul, 1483618774ul, 479157358ul, 241910185ul, 1816847951ul, 294238147ul, 751378565ul, 950677968ul, 1353687425ul, 2099537820ul, 489657623ul, 1206561978ul, 1446890908ul, 670585330ul, 1673691826ul, 528358449ul, 388757617ul, 920117849ul, 1034587532ul, 1133951169ul, 2101537119ul, 111610561ul, 84018609ul, 1142731436ul, 355746985ul, 1874726729ul, 1558257196ul, 1396142828ul, 13951104ul, 672827403ul, 356174774ul, 703385972ul, 678758177ul, 1845881355ul, 320346298ul, 120350833ul, 2076402856ul, 2098837679ul, 1558505958ul, 749935498ul, 872552596ul, 2028108902ul, 803498005ul, 646691955ul, 1045021806ul, 1388148489ul, 2090182870ul, 1721321144ul, 811003409ul, 387890129ul, 1471453225ul, 152160409ul, 721858990ul, 1974450674ul, 1266442113ul, 1434651133ul, 52613790ul, 957785065ul, 1315889798ul, 795919808ul, 808319316ul, 708185222ul, 221163346ul, 1312760494ul, 1549587230ul, 1519396596ul, 2008628746ul, 2134440466ul, 2029796284ul, 304006647ul, 1399196959ul, 1159385586ul, 373788295ul, 1570990724ul, 1087431084ul, 640551111ul, 2013188569ul, 20676264ul, 338094193ul, 1141640068ul, 676349781 }   
};
      
unsigned long __next_prime(unsigned long __n)
{
   unsigned int i;
   assert(&__n);
   
   for (i=0; i<sizeof(__primeset)/sizeof(unsigned long); i++) {
      if (__primeset[i] > __n)
         return __primeset[i];
   }
   return 0;
}


static unsigned long additiveHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = len;
   assert(key && len > 0);
   for (i = 0; i < len; i++)
      hash += key[i];
   return (hash % __primeset[23]);
}

static unsigned long rotatingHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = len;
   assert(key && len > 0);
   for (i = 0; i < len; i++)
      hash = (hash<<4)^(hash>>28)^key[i];

   return (hash ^ (hash>>10) ^ (hash>>20));
}


static unsigned long oneByOneHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = 0;
   assert(key && len > 0);
   for (i = 0; i < len; i++) {
      hash += key[i];
      hash += (hash << 10);
      hash ^= (hash >> 6);
   }
   hash += (hash << 3);
   hash ^= (hash >> 11);
   hash += (hash << 15);
   return hash;
}

static unsigned long bernsteinHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = 0;
   assert(key && len > 0);
   for (i = 0; i < len; i++) 
      hash = 33*hash + key[i];
   return hash;
}

static unsigned long CRCHash(unsigned char * key, int len)     
{                                                       
   int i;
   unsigned long hash = len;                                        
   assert(key && len > 0);
   for (i = 0; i < len; i++)                       
      hash = (hash >> 8) ^ __tableset[1][(hash & 0xff) ^ key[i]];   
   return hash;                                 
}  

static unsigned long universalHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = len;
   assert(key && len > 0);

   for (i=0; i<(len<<3); i+=8) {
      unsigned char k = key[i>>3];
      if ((k&0x01) == 0) hash ^= __tableset[2][i+0];
      if ((k&0x02) == 0) hash ^= __tableset[2][i+1];
      if ((k&0x04) == 0) hash ^= __tableset[2][i+2];
      if ((k&0x08) == 0) hash ^= __tableset[2][i+3];
      if ((k&0x10) == 0) hash ^= __tableset[2][i+4];
      if ((k&0x20) == 0) hash ^= __tableset[2][i+5];
      if ((k&0x40) == 0) hash ^= __tableset[2][i+6];
      if ((k&0x80) == 0) hash ^= __tableset[2][i+7];
   }
   return hash;
}         

static unsigned long ZobristHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = len; 
   assert(key && len > 0);
   for (i = 0; i < len; i++) 
      hash ^= __tableset[i&7][key[i]];
   return hash;
}

static unsigned long FNVHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = (unsigned long)2166136261UL; 
   const unsigned long p = 16777619;
   assert(key && len > 0);
   
   for (i = 0; i < len; i++) 
      hash = (hash ^ key[i]) * p;
   hash += hash << 13;
   hash ^= hash >> 7;
   hash += hash << 3;
   hash ^= hash >> 17;
   hash += hash << 5;
   return hash;
}

static unsigned long javaHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = 0; 
   assert(key && len > 0);
   for (i = 0; i < len; i++) 
      hash = 31 * hash + key[i];
   return hash;
}

static unsigned long PJWHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = 0; 
   
   int BitsInUnsignedInt = 32;
   int ThreeQuarters     = (BitsInUnsignedInt * 3) / 4;
   int OneEighth         = BitsInUnsignedInt / 8;
   int HighBits          = 0xFFFFFFFF << (BitsInUnsignedInt - OneEighth);
   int test              = 0;
   assert(key && len > 0);

   for (i = 0; i < len; i++) {
      hash = (hash << OneEighth) + key[i]; 
      if((test = hash & HighBits) != 0) 
         hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits)); 
   }

   return (hash & 0x7FFFFFFF);
}

static unsigned long JSHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = 1315423911;
   assert(key && len > 0);

   for (i = 0; i < len; i++) 
      hash ^= ((hash << 5) + key[i] + (hash >> 2)); 

   return (hash & 0x7FFFFFFF);
}

static unsigned long RSHash(unsigned char * key, int len)
{
   int i;
   unsigned long hash = 0;
   int b    = 378551;
   int a    = 63689; 
   assert(key && len > 0);

   for (i = 0; i < len; i++) {
      hash = hash * a + key[i];
      a = a * b;
   }

   return (hash & 0x7FFFFFFF);
}

unsigned long calucate_hash(unsigned char * key, int len)
{ 
   unsigned long s = 0;
   assert(key && len > 0);
   s += additiveHash(key, len);
   s += rotatingHash(key, len); 
   s += oneByOneHash(key, len); 
   s += bernsteinHash(key, len); 
   s += CRCHash(key, len); 
   s += universalHash(key, len); 
   s += ZobristHash(key, len); 
   s += FNVHash(key, len); 
   s += javaHash(key, len); 
   s += PJWHash(key, len); 
   s += JSHash(key, len); 
   s += RSHash(key, len);
   return s;
}

unsigned long additiveHash(unsigned char * key, int len);
unsigned long rotatingHash(unsigned char * key, int len); 
unsigned long oneByOneHash(unsigned char * key, int len); 
unsigned long bernsteinHash(unsigned char * key, int len); 
unsigned long CRCHash(unsigned char * key, int len); 
unsigned long universalHash(unsigned char * key, int len); 
unsigned long ZobristHash(unsigned char * key, int len); 
unsigned long FNVHash(unsigned char * key, int len); 
unsigned long javaHash(unsigned char * key, int len); 
unsigned long PJWHash(unsigned char * key, int len); 
unsigned long JSHash(unsigned char * key, int len); 
unsigned long RSHash(unsigned char * key, int len);

#ifdef __cplusplus
}
#endif


